﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    public class MG0:Group
    {

        ///常规输入输出文件
        #region subgroup a


        string m_GEODAT = "GEO.DAT";
        /// <summary>
        /// 数据文件地址,输入文件,geo.dat
        /// </summary>
        public string GEODAT
        {
            get { return m_GEODAT; }
            set { m_GEODAT = value; }
        }


        string m_SRFDAT = "SURF.DAT";
        /// <summary>
        /// 地面气象文件,输入文件,surf.dat
        /// </summary>
        public string SRFDAT
        {
            get { return m_SRFDAT; }
            set { m_SRFDAT = value; }
        }



        string m_CLDDAT = "CLDDAT.dat";
        /// <summary>
        ///  CLOUD,云层 文件,输入文件,CLOUD.DAT
        /// </summary>
        public string CLDDAT
        {
            get { return m_CLDDAT; }
            set { m_CLDDAT = value; }
        }


        string m_PRCDAT = "PRECIP.DAT";
        /// <summary>
        /// 小时降雨文件,输入文件,PRECIP.DAT
        /// </summary>
        public string PRCDAT
        {
            get { return m_PRCDAT; }
            set { m_PRCDAT = value; }
        }

        /// <summary>
        /// 地形权重文件,看情况需要，默认设置为无
        /// </summary>
        string m_WTDAT = "";
        public string WTDAT
        {
            get { return m_WTDAT; }
            set { m_WTDAT = value; }
        }

        string m_METLST = "CALMET.lst";
        /// <summary>
        /// 输出列表，包含摘要信息， 输出文件,CALMET.LST
        /// </summary>
        public string METLST
        {
            get { return m_METLST; }
            set { m_METLST = value; }
        }


        string m_METDAT = "CALMET.DAT";
        /// <summary>
        /// 输出的气象数据文件，输出文件,CALMET.DAT
        /// </summary>
        public string METDAT
        {
            get { return m_METDAT; }
            set { m_METDAT = value; }
        }



        string m_PACDAT = "";
        /// <summary>
        /// 输出文件，暂时未知，PACOUT.DAT
        /// </summary>
        public string PACDAT
        {
            get { return m_PACDAT; }
            set { m_PACDAT = value; }
        }




        bool m_LCFILES = false;
        /// <summary>
        /// 是否将文件名等转化为小写字母，默认为F, T = lower case      , F = UPPER CASE ,窗体现在没有与之对应，现默认小写
        /// </summary>
        public bool LCFILES
        {
            get { return m_LCFILES; }
            set { m_LCFILES = value; }
        }



        int m_NUSTA = 0;
        /// <summary>
        /// 高空数据站点个数
        /// </summary>
        public int NUSTA
        {
            get { return m_NUSTA; }
            set { m_NUSTA = value; }
        }



        int m_NOWSTA = 0;
        /// <summary>
        /// 海洋测站气象站点个数
        /// </summary>
        public int NOWSTA
        {
            get { return m_NOWSTA; }
            set { m_NOWSTA = value; }
        }


        int m_NM3D = 0;
        /// <summary>
        ///  Number of MM4/MM5/3D.DAT files,风场文件个数
        /// </summary>
        public int NM3D
        {
            get { return m_NM3D; }
            set { m_NM3D = value; }
        }



        int m_NIGF = 0;
        /// <summary>
        ///  Number of IGF-CALMET.DAT files。未找到与之对应关系，有待解决
        /// </summary>
        public int NIGF
        {
            get { return m_NIGF; }
            set { m_NIGF = value; }
        }


        #endregion


        ///探空数据文件，每个站点一个数据文件
        #region subgroup b

        //Upper air files (one per station) 每个文件对应一个站点,输入文件
        List<string> m_UPDAT = new List<string>();
        /// <summary>
        /// 探空数据文件，每个站点一个数据文件,集合，UP1.DAT,UP2.DAT,UP3.DAT....
        /// </summary>
        public List<string> UPDAT
        {
            get { return m_UPDAT; }
            set { m_UPDAT = value; }
        }



        #endregion

        ///海洋测站数据，每个站点一个数据文件，中国区域暂时没发现可用数据
        #region subgroup c

        // Overwater station files (one per station)
        List<string> m_SEADAT = new List<string>();
        /// <summary>
        /// 海洋测站数据，集合，每个站点一个数据文件，中国区域暂时没发现可用数据
        /// </summary>
        public List<string> SEADAT
        {
            get { return m_SEADAT; }
            set { m_SEADAT = value; }
        }


        #endregion

        ///MM5数据
        #region subgroup d

        //MM4/MM5/3D.DAT files (consecutive or overlapping)
        List<string> m_M3DDAT = new List<string>();
        /// <summary>
        /// MM5数据文件，要求mm5数据连续的或者重叠
        /// </summary>
        public List<string> M3DDAT
        {
            get { return m_M3DDAT; }
            set { m_M3DDAT = value; }
        }
        #endregion

        ///IGF-CALMET.DAT files
        #region subgroup e

        //  IGF-CALMET.DAT files (consecutive or overlapping)

        List<string> m_IGFDAT = new List<string>();
        /// <summary>
        /// IGF-CALMET.DAT files (consecutive or overlapping)
        /// </summary>
        public List<string> IGFDAT
        {
            get { return m_IGFDAT; }
            set { m_IGFDAT = value; }
        }


        #endregion



        //下面的变量还没有进行充足的注释
        /// <summary>
        /// 子组F，其他输入和输出文件
        /// </summary>
        #region subgroup f

        string m_DIADAT = "DIAG.DAT";
        /// <summary>
        /// 预处理的地面和探空数据文件，Diag.DAT,输入文件，格式暂时未知，可参考calmet user guide
        /// </summary>
        public string DIADAT
        {
            get { return m_DIADAT; }
            set { m_DIADAT = value; }
        }
        string m_PRGDAT = "";
        /// <summary>
        /// CSUMM诊断风场模型的文件，PROG.DAT,输入文件。未找到与之相对就关系，前面的解释或许是下错误
        /// </summary>
        public string PRGDAT
        {
            get { return m_PRGDAT; }
            set { m_PRGDAT = value; }
        }


        //以下是风场模型测试和调试文件，输出文件，
        string m_TSTPRT = "";
        /// <summary>
        /// 中间风参数，输入和内部参数
        /// </summary>
        public string TSTPRT
        {
            get { return m_TSTPRT; }
            set { m_TSTPRT = value; }
        }
        string m_TSTOUT = "";
        /// <summary>
        /// 最终风场
        /// </summary>
        public string TSTOUT
        {
            get { return m_TSTOUT; }
            set { m_TSTOUT = value; }
        }
        string m_TSTKIN = "";
        /// <summary>
        /// 运动学调整后的风场
        /// </summary>
        public string TSTKIN
        {
            get { return m_TSTKIN; }
            set { m_TSTKIN = value; }
        }
        string m_TSTFRD = "";
        /// <summary>
        /// Froude效应调整的风场
        /// </summary>
        public string TSTFRD
        {
            get { return m_TSTFRD; }
            set { m_TSTFRD = value; }
        }
        string m_TSTSLP = "";
        /// <summary>
        /// 坡风效应调整后的风场
        /// </summary>
        public string TSTSLP
        {
            get { return m_TSTSLP; }
            set { m_TSTSLP = value; }
        }
        string m_DCSTGD = "";
        /// <summary>
        /// 输出文件，作用未知,在INPUT GROUP: 0 Subgroup (f)里 
        /// </summary>
        public string DCSTGD
        {
            get { return m_DCSTGD; }
            set { m_DCSTGD = value; }
        }

        #endregion





        public override   string WriteToGroup()
        {
            //StrWriter.GetKeyValStr("geodat", "hlo.dat");
            //StrWriter.GetNullKeyValStr;
            //StrWriter.GetCLine();


            string Subgroup_a = "", TempStr;
            TempStr = "INPUT GROUP: 0 -- Input and Output File Names\r\n";
            Subgroup_a += TempStr;

            TempStr = "Subgroup (a)\r\n";
            Subgroup_a += TempStr;


            if (GEODAT != "")
                TempStr = StrWriter.GetKeyValStr("GEODAT", GEODAT);
            else
                TempStr = StrWriter.GetNullKeyValStr("GEODAT");
            Subgroup_a += TempStr;


            if (SRFDAT != "")
                TempStr = StrWriter.GetKeyValStr("SRFDAT", SRFDAT);
            else
                TempStr = StrWriter.GetNullKeyValStr("SRFDAT");
            Subgroup_a += TempStr;

            if (CLDDAT != "")
                TempStr = StrWriter.GetKeyValStr("CLDDAT", CLDDAT);
            else
                TempStr = StrWriter.GetNullKeyValStr("CLDDAT");
            Subgroup_a += TempStr;

            if (PRCDAT != "")
                TempStr = StrWriter.GetKeyValStr("PRCDAT", PRCDAT);
            else
                TempStr = StrWriter.GetNullKeyValStr("PRCDAT");
            Subgroup_a += TempStr;

            if (WTDAT != "")
                TempStr = StrWriter.GetKeyValStr("WTDAT", WTDAT);
            else
                TempStr = StrWriter.GetNullKeyValStr("WTDAT");
            Subgroup_a += TempStr;

            if (METLST != "")
                TempStr = StrWriter.GetKeyValStr("METLST", METLST);
            else
                TempStr = StrWriter.GetNullKeyValStr("METLST");
            Subgroup_a += TempStr;

            if (METDAT != "")
                TempStr = StrWriter.GetKeyValStr("METDAT", METDAT);
            else
                TempStr = StrWriter.GetNullKeyValStr("METDAT");
            Subgroup_a += TempStr;

            if (PACDAT != "")
                TempStr = StrWriter.GetKeyValStr("PACDAT", PACDAT);
            else
                TempStr = StrWriter.GetNullKeyValStr("PACDAT");
            Subgroup_a += TempStr;


            if (LCFILES == false)
                TempStr = "! LCFILES = " + "F !" + "\r\n";
            else
                TempStr = "! LCFILES = " + "T !" + "\r\n";
            Subgroup_a += TempStr;

            TempStr = "NUMBER OF UPPER AIR & OVERWATER STATIONS:\r\n";
            Subgroup_a += TempStr;

            TempStr = "! NUSTA =  " + NUSTA.ToString() + " !" + "\r\n";
            Subgroup_a += TempStr;

            TempStr = "! NOWSTA  =  " + NOWSTA.ToString() + " !" + "\r\n";
            Subgroup_a += TempStr;

            TempStr = "NUMBER OF PROGNOSTIC and IGF-CALMET FILEs:\r\n";
            Subgroup_a += TempStr;



            TempStr = "! NM3D  =  " + NM3D.ToString() + " !" + "\r\n";
            Subgroup_a += TempStr;

            TempStr = "! NIGF   =  " + NIGF.ToString() + " !" + "\r\n";
            Subgroup_a += TempStr;

            TempStr = "! END !" + "\r\n";
            Subgroup_a += TempStr;

            TempStr = StrWriter.GetCLine();
            Subgroup_a += TempStr;

            //=================================================
            //写入探空数据文件
            string Subgroup_b = "";


            TempStr = "Subgroup (b)" + "\r\n";
            Subgroup_b += TempStr;

            TempStr = "Upper air files (one per station)" + "\r\n";
            Subgroup_b += TempStr;

            if (UPDAT.Count > 0)
            {
                TempStr = "";
                foreach (string str in UPDAT)
                {
                    if (str != "")
                    {
                        TempStr += "! UPDAT=" + str + "!" + "  !END!" + "\r\n"; //小杨修改

                    }
                    else
                    {
                        TempStr += "* UPDAT=" + " *" + "\r\n";

                    }
                    //Subgroup_b += TempStr;  

                }
                Subgroup_b += TempStr;

                // TempStr = "!END!" + "\r\n";
                TempStr = "\r\n";
                Subgroup_b += TempStr;
            }




            TempStr = StrWriter.GetCLine();
            Subgroup_b += TempStr;

            //==================================================

            string Subgroup_c = "";

            TempStr = "Subgroup (c)" + "\r\n";
            Subgroup_c += TempStr;

            TempStr = "Overwater station files (one per station)" + "\r\n";
            Subgroup_c += TempStr;

            if (SEADAT.Count > 0)
            {
                foreach (string str in SEADAT)
                {
                    if (str != "")
                    {
                        TempStr = "! SEADAT=" + str + "!" + "\r\n";

                    }
                    else
                    {
                        TempStr = "* SEADAT=" + " *" + "\r\n";
                    }
                    Subgroup_c += TempStr;
                }

                TempStr = "!END!" + "\r\n";
                Subgroup_c += TempStr;
            }




            TempStr = StrWriter.GetCLine();
            Subgroup_c += TempStr;

            //====================================================
            //写入MM5文件路径


            string Subgroup_d = "";

            TempStr = "Subgroup (d)" + "\r\n";
            Subgroup_d += TempStr;

            TempStr = "MM4/MM5/3D.DAT files (consecutive or overlapping)" + "\r\n";
            Subgroup_d += TempStr;




            if (M3DDAT.Count > 0)
            {
                foreach (string str in M3DDAT)
                {
                    if (str != "")
                    {
                        TempStr = "! M3DDAT=" + str + "!" + "  !END!" + "\r\n";
                    }
                    else
                    {
                        TempStr = "* M3DDAT=" + " *" + "\r\n";
                    }
                    Subgroup_d += TempStr;
                }

                TempStr = "\r\n";

                Subgroup_d += TempStr;

            }



            TempStr = StrWriter.GetCLine();
            Subgroup_d += TempStr;

            //===================================================

            string Subgroup_e = "";

            TempStr = "Subgroup (e)" + "\r\n";
            Subgroup_e += TempStr;

            TempStr = "IGF-CALMET.DAT files (consecutive or overlapping)" + "\r\n";
            Subgroup_e += TempStr;

            if (IGFDAT.Count > 0)
            {
                foreach (string str in IGFDAT)
                {
                    if (str != "")
                    {
                        TempStr = "! IGFDAT=" + str + "!" + "\r\n";
                    }
                    else
                    {
                        TempStr = "* IGFDAT=" + " *" + "\r\n";
                    }
                    Subgroup_d += TempStr;
                }


                TempStr = "!END!" + "\r\n";
                Subgroup_e += TempStr;

            }


            TempStr = StrWriter.GetCLine();
            Subgroup_e += TempStr;

            //===================================================

            string Subgroup_f = "";

            TempStr = "Subgroup (f)" + "\r\n";
            Subgroup_f += TempStr;

            TempStr = "Other file names" + "\r\n";
            Subgroup_f += TempStr;

            if (DIADAT != "")
                TempStr = StrWriter.GetKeyValStr("DIADAT", DIADAT);
            else
                TempStr = StrWriter.GetNullKeyValStr("DIADAT");
            Subgroup_f += TempStr;


            if (PRGDAT != "")
                TempStr = StrWriter.GetKeyValStr("PRGDAT", PRGDAT);
            else
                TempStr = StrWriter.GetNullKeyValStr("PRGDAT");
            Subgroup_f += TempStr;

            if (TSTPRT != "")
                TempStr = StrWriter.GetKeyValStr("TSTPRT", TSTPRT);
            else
                TempStr = StrWriter.GetNullKeyValStr("TSTPRT");
            Subgroup_f += TempStr;

            if (TSTOUT != "")
                TempStr = StrWriter.GetKeyValStr("TSTOUT", TSTOUT);
            else
                TempStr = StrWriter.GetNullKeyValStr("TSTOUT");
            Subgroup_f += TempStr;

            if (TSTKIN != "")
                TempStr = StrWriter.GetKeyValStr("TSTKIN", TSTKIN);
            else
                TempStr = StrWriter.GetNullKeyValStr("TSTKIN");
            Subgroup_f += TempStr;

            if (TSTFRD != "")
                TempStr = StrWriter.GetKeyValStr("TSTFRD", TSTFRD);
            else
                TempStr = StrWriter.GetNullKeyValStr("TSTFRD");
            Subgroup_f += TempStr;

            if (TSTSLP != "")
                TempStr = StrWriter.GetKeyValStr("TSTSLP", TSTSLP);
            else
                TempStr = StrWriter.GetNullKeyValStr("TSTSLP");
            Subgroup_f += TempStr;

            if (DCSTGD != "")
                TempStr = StrWriter.GetKeyValStr("DCSTGD", DCSTGD);
            else
                TempStr = StrWriter.GetNullKeyValStr("DCSTGD");
            Subgroup_f += TempStr;

            TempStr = "!END!" + "\r\n";
            Subgroup_f += TempStr;

            TempStr = StrWriter.GetCLine();
            Subgroup_f += TempStr;

            //========================================================

            string InputGroup;
            InputGroup = Subgroup_a + Subgroup_b + Subgroup_c + Subgroup_d + Subgroup_e + Subgroup_f;


            return InputGroup;

        }

        public override  void ReadFromGroup(Dictionary<string, string> dic)
        {
            foreach (KeyValuePair<string, string> m_dic in dic)
            {
                if (m_dic.Key == "GEODAT")
                {
                    this.GEODAT = m_dic.Value;
                }
                if (m_dic.Key == "SRFDAT")
                {
                    this.SRFDAT = m_dic.Value;
                }
                if (m_dic.Key == "CLDDAT")
                {
                    this.CLDDAT = m_dic.Value;
                }
                if (m_dic.Key == "PRCDAT")
                {
                    this.PRCDAT = m_dic.Value;
                }
                if (m_dic.Key == "WTDAT")
                {
                    this.WTDAT = m_dic.Value;
                }
                if (m_dic.Key == "METLST")
                {
                    this.METLST = m_dic.Value;
                }
                if (m_dic.Key == "METDAT")
                {
                    this.METDAT = m_dic.Value;
                }
                if (m_dic.Key == "PACDAT")
                {
                    this.PACDAT = m_dic.Value;
                }
                if (m_dic.Key == "LCFILES")
                {
                    if (m_dic.Value == "T")
                    {
                        this.LCFILES = true;
                    }
                    else
                    {
                        this.LCFILES = false;
                    }

                }
                if (m_dic.Key == "NUSTA")
                {
                    this.NUSTA = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "NOWSTA")
                {
                    this.NOWSTA = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "NM3D")
                {
                    this.NM3D = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "NIGF")
                {
                    this.NIGF = Convert.ToInt32(m_dic.Value);
                }
                //b
                if (m_dic.Key == "UPDAT")
                {
                    this.UPDAT = StrWriter.ReturnStrList(m_dic.Value);
                }
                if (m_dic.Key == "SEADAT")
                {
                    this.UPDAT = StrWriter.ReturnStrList(m_dic.Value);
                }
                if (m_dic.Key == "M3DDAT")
                {
                    this.UPDAT = StrWriter.ReturnStrList(m_dic.Value);
                }
                if (m_dic.Key == "IGFDAT")
                {
                    this.UPDAT = StrWriter.ReturnStrList(m_dic.Value);
                }
                //f
                if (m_dic.Key == "DIADAT")
                {
                    this.DIADAT = m_dic.Value;
                }
                if (m_dic.Key == "PRGDAT")
                {
                    this.PRGDAT = m_dic.Value;
                }
                if (m_dic.Key == "TSTPRT")
                {
                    this.TSTPRT = m_dic.Value;
                }
                if (m_dic.Key == "TSTOUT")
                {
                    this.TSTOUT = m_dic.Value;
                }
                if (m_dic.Key == "TSTKIN")
                {
                    this.TSTKIN = m_dic.Value;
                }
                if (m_dic.Key == "TSTFRD")
                {
                    this.TSTFRD = m_dic.Value;
                }
                if (m_dic.Key == "TSTSLP")
                {
                    this.TSTSLP = m_dic.Value;
                }
                if (m_dic.Key == "DCSTGD")
                {
                    this.DCSTGD = m_dic.Value;
                }
            }
        }

    }
}
